#include <iostream>
#include <vector>
#include <algorithm>

class Solution {
public:
    static bool check(const std::vector<int>& time, int totalTrips, long long t) {
        long long cnt = 0;
        for (size_t i = 0; i < time.size(); ++i) {
            cnt += t / time[i];
        }
        return cnt >= totalTrips;
    }

    long long minimumTime(std::vector<int>& time, int totalTrips) {
        int maxTime = 0;
        for (size_t i = 0; i < time.size(); ++i) {
            if (time[i] > maxTime) {
                maxTime = time[i];
            }
        }
        long long l = 1;
        long long r = (long long)totalTrips * maxTime;
        while (l < r) {
            long long mid = l + (r - l) / 2;
            if (check(time, totalTrips, mid)) {
                r = mid;
            } else {
                l = mid + 1;
            }
        }
        return l;
    }
};
int main() {
    Solution sol;
    {
        int arr1[] = {1, 2, 3};
        std::vector<int> time1(arr1, arr1 + sizeof(arr1) / sizeof(arr1[0]));
        int totalTrips1 = 5;
        long long result1 = sol.minimumTime(time1, totalTrips1);
        std::cout << "Test 1: Minimum time for " << totalTrips1 << " trips is " << result1 << " (Expected: 3)" << std::endl;
    }
    {
        int arr2[] = {2};
        std::vector<int> time2(arr2, arr2 + sizeof(arr2) / sizeof(arr2[0]));
        int totalTrips2 = 1;
        long long result2 = sol.minimumTime(time2, totalTrips2);
        std::cout << "Test 2: Minimum time for " << totalTrips2 << " trips is " << result2 << " (Expected: 2)" << std::endl;
    }
    {
        int arr3[] = {5, 10, 15};
        std::vector<int> time3(arr3, arr3 + sizeof(arr3) / sizeof(arr3[0]));
        int totalTrips3 = 10;
        long long result3 = sol.minimumTime(time3, totalTrips3);
        std::cout << "Test 3: Minimum time for " << totalTrips3 << " trips is " << result3 << " (Expected: 20)" << std::endl;
    }
    return 0;
}
